﻿Public Class CLabelCheckState4 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CLabelCheckState4.IsEnter")
        If CCommon.isInStr(task.ActionCd, "LINTOLABEL", "LABEL") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase = Nothing
        Dim pdaTask As CPDATask4 = DirectCast(task, CPDATask4)
        Debug.WriteLine("CLabelCheckState4.DoExecute")



        Dim AppManager As CApplicationManager = CApplicationManager.GetInstance

        If Not pdaTask.isSendStartFlag Then
            ''自動送信機能をONにする
            pdaTask.isSendStartFlag = True
            pdaTask.WindowManager.AutoSend()
        End If

        Do While task.ProcessText = ""
            '' リーダーからデータを取得する(待ち時間制限なし)
            pdaTask.WindowManager.SetMessage(CCommon.CNS_MSG_011, CCommon.COLOR_BLACK, CCommon.COLOR_GREEN)
            task.ProcessText = task.ReadTextWait(-1)
        Loop



        Select Case CBarcode.GetBarcodeType(task.ProcessText)
            Case EnumBarcodeType.INNER_LABEL_CODE
                '' 社内ラベルの場合
                task.ActionCd = "LABEL-IN"
            Case EnumBarcodeType.INNER_DELIVERY
                '' 社内納品書の場合
                task.ActionCd = "LABEL-ID"
            Case EnumBarcodeType.END_LABEL_CODE
                ''ラベル読込終了

                pdaTask.clearUniqueCd()
                Try
                    Select Case pdaTask.StateType
                        Case 3
                            pdaTask.C_FileCommon.AddTrxUniqueCd4In(pdaTask.getSendUniqueCd())
                        Case 4
                            pdaTask.C_FileCommon.AddTrxUniqueCd4Out(pdaTask.getSendUniqueCd())
                    End Select

                Catch ex As Exception

                End Try
                pdaTask.isSendingFlag = True
                Try
                    pdaTask.C_FileCommon.AddTrxINOUT(pdaTask.getSendActionData())
                    Select Case pdaTask.StateType
                        Case 3
                            pdaTask.C_FileCommon.SendTrxINOUT("IN")
                        Case 4
                            pdaTask.C_FileCommon.SendTrxINOUT("OUT")
                    End Select
                Catch ex As Exception

                End Try


                pdaTask.WindowManager.BaseRelease()

                pdaTask.WindowManager.ClearActionLabel()


                pdaTask.DataList = Nothing

                pdaTask.WindowManager.CloseWindow()

            Case EnumBarcodeType.EMP_CODE


                ''名札自由読込
                ''交代
                Dim empDAO As CEmpDAO = CEmpDAO.GetInstance()
                Dim empData As strctEmpInfo = empDAO.GetEmpInfo(task.ProcessText)
                pdaTask.EmpInfo.empNo = empData.EmpCd
                pdaTask.EmpInfo.empName = empData.EmpName
                pdaTask.WindowManager.SetEmpInfo(pdaTask.EmpInfo.empNo & ":[" & pdaTask.EmpInfo.empName & "]")

                task.ActionCd = "LABEL"
                task.ProcessText = ""
            Case EnumBarcodeType.IRREGULAR_CODE
                ''各種コード
                task.ActionCd = "IRREGULAR"
            Case Else
                pdaTask.alertMsg(CCommon.CNS_MSG_061, task)

                task.ActionCd = "LABEL"
                task.ProcessText = ""
        End Select

        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CLabelCheckState.DoExit")
        Return True
    End Function


End Class
